﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using rock.Model;
using rock.DAL;
using rock.UI.common;
using rock.BLL;

namespace rock.UI.houseinfo
{
    public partial class FormRentCustomUpdate : Form
    {
 


        ModelRENT_CUSTOM modelRENT_CUSTOM = new ModelRENT_CUSTOM();
        public ModelRENT_CUSTOM _ModelRENT_CUSTOM
        {
            get
            {
                return modelRENT_CUSTOM;
            }
            set
            {
                modelRENT_CUSTOM = value;
            }
        }
        DalRENT_CUSTOM dalRENT_CUSTOM = new DalRENT_CUSTOM();

        public FormRentCustomUpdate()
        {
            InitializeComponent();
            this.AcceptButton = this.button1;
            this.CancelButton = this.button2;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.WindowState = FormWindowState.Normal;
            this.StartPosition = FormStartPosition.CenterScreen;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Icon = global::rock.Properties.Resources.house;
        }

        private void FormRentCustomUpdate_Load(object sender, EventArgs e)
        {
            //this.textBox1Name.Text = this._ModelHOUSE_XIAOQU.NAME;
            this.textBox1NAME.Text = this._ModelRENT_CUSTOM.NAME;
            this.textBox2PHONE.Text = this._ModelRENT_CUSTOM.PHONE;
            this.textBox3ADDRESS.Text = this._ModelRENT_CUSTOM.ADDRESS;
            this.textBox4LINK_MAN.Text = this._ModelRENT_CUSTOM.LINK_MAN;
            this.textBox5CARDID.Text = this._ModelRENT_CUSTOM.CARDID;
            this.textBox6LOWER_MAN.Text = this._ModelRENT_CUSTOM.LOWER_MAN;
            this.textBox7BUSINESS_LICENSE.Text = this._ModelRENT_CUSTOM.BUSINESS_LICENSE;
            this.textBox8BRAND.Text = this._ModelRENT_CUSTOM.BRAND;
            this.textBox9WHOINROOM.Text = this._ModelRENT_CUSTOM.WHOINROOM;
            this.radioButton1TYPE.Checked = this._ModelRENT_CUSTOM.TYPE == 0 ? true : false;
            this.radioButton2TYPE.Checked = this._ModelRENT_CUSTOM.TYPE == 0 ? false : true;

            radioButton2TYPE_CheckedChanged(null , null);

        }

        private Boolean check()
        {
            try
            {//dalRENT_CUSTOM
                StringUtils.checkText(this.textBox1NAME.Text, 2, 30, "客户姓名");

                  
                StringUtils.checkText(this.textBox5CARDID.Text, 0, 30, "身份证");
                StringUtils.checkText(this.textBox2PHONE.Text, 0, 30, "电话");
                StringUtils.checkText(this.textBox4LINK_MAN.Text, 0, 30, "联系人");
                StringUtils.checkText(this.textBox3ADDRESS.Text, 0, 30, "地址");
                StringUtils.checkText(this.textBox6LOWER_MAN.Text, 0, 30, "法人姓名");
                StringUtils.checkText(this.textBox7BUSINESS_LICENSE.Text, 0, 30, "宫业执照");
                StringUtils.checkText(this.textBox8BRAND.Text, 0, 30, "品牌名称");

                StringUtils.checkText(this.textBox9WHOINROOM.Text, 0, 300, "备注信息");
                StringUtils.checkText(this.textBox1NETE.Text, 0, 300, "备注信息");

                ////更新.原值不检测
                //if (dalRENT_CUSTOM.Exists(this._ModelRENT_CUSTOM.SEQID))
                //{
                //    if (this._ModelRENT_CUSTOM.Equals(this.textBox1NAME.Text.Trim()))
                //    {
                //        return true;
                //    }
                //}
                //String existSql = "select count(1) from HOUSE_XIAOQU where NAME = '{0}'";
                //existSql = String.Format(existSql, this.textBox1Name.Text);
                //if (BllCommonUtil.Exists(existSql))
                //{
                //    MessageBox.Show("此市场名称值已存在在,请输入其它的值");
                //    return false;
                //}


            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "提示");
                return false;
            }
            return true;
        }


        private void button1_Click(object sender, EventArgs e)
        {
            if (!check())
            {
                return;
            }

            this._ModelRENT_CUSTOM.NAME = this.textBox1NAME.Text  ;
            this._ModelRENT_CUSTOM.PHONE=this.textBox2PHONE.Text ;
            this._ModelRENT_CUSTOM.ADDRESS=  this.textBox3ADDRESS.Text ;
            this._ModelRENT_CUSTOM.LINK_MAN=  this.textBox4LINK_MAN.Text;
            this._ModelRENT_CUSTOM.CARDID= this.textBox5CARDID.Text ;
            this._ModelRENT_CUSTOM.LOWER_MAN=  this.textBox6LOWER_MAN.Text ;
            this._ModelRENT_CUSTOM.BUSINESS_LICENSE=  this.textBox7BUSINESS_LICENSE.Text;
            this._ModelRENT_CUSTOM.BRAND= this.textBox8BRAND.Text;
            this._ModelRENT_CUSTOM.WHOINROOM= this.textBox9WHOINROOM.Text ;
            if (this.radioButton1TYPE.Checked) {
                this._ModelRENT_CUSTOM.TYPE = 0;
            }else{
                this._ModelRENT_CUSTOM.TYPE = 1;
            }


            if (dalRENT_CUSTOM.Exists(this._ModelRENT_CUSTOM.SEQID))
            {
                dalRENT_CUSTOM.Update(this._ModelRENT_CUSTOM);
            }
            else
            {
                dalRENT_CUSTOM.Add(this._ModelRENT_CUSTOM);
            }
            //触发代理
            oneRefreshParentData(1);
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //代理
        public delegate void RefreshParentData(int pageno);
        public RefreshParentData oneRefreshParentData;

        private void button1_Click_1(object sender, EventArgs e)
        {
            button1_Click(sender, e);
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            button2_Click(sender, e);
        }

        private void radioButton2TYPE_CheckedChanged(object sender, EventArgs e)
        {
                if (radioButton1TYPE.Checked)
                {
                    this.groupBox1.Enabled = false;
                }
                else 
                {
                    this.groupBox1.Enabled = true;
                }
            
        }

        private void label8_Click(object sender, EventArgs e)
        {

        }

        private void textBox8BRAND_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
